<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>分单销账列表</title>
        <% include("/common/common_css_js.html"){} %>
    </head>
    <body>
        <div style="padding-bottom: 5px;">
            <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
                <span class="separator"></span>
                <span>发货人:</span>
                <div id="keyCustomerId" name="keyCustomerId" class="mini-autocomplete" style="width:250px;"  popupWidth="1000" textField="name" valueField="id"
                     url="${base}/pages/customer_manage/queryDeliveryCustomerByKey"  required="true" requiredErrorText="发货人不能为空"
                     searchField="key"
                     emptyText="发货人名称">
                    <div property="columns">
                        <div header="客户名称" field="name"></div>
                        <div header="客户简称" field="shortName"></div>
                        <div header="客户电话" field="phone"></div>
                        <div header="客户地址" field="address"></div>
                    </div>
                </div>

                <div style="margin-top: 5px"></div>
                <% if(so.hasPermission("reverseList:query")){%>
                    <a class="mini-button" iconCls="icon-search" onclick="searchReverse()">查询</a>
                <% } %>

                <% if(so.hasPermission("reverseList:queryCndClear")){%>
                    <a class="mini-button" iconCls="icon-new" onclick="clearSearch('queryForm')">清空查询条件</a>
                <% } %>

                <span class="separator"></span>

                <% if(so.hasPermission("reverseList:download")){%>
                    <#download_grid id="downloadGrid" theGridId="datagrid1" theFileName="销账发货人可用金额汇总表"/>
                <% } %>

            </div>
        </div>

        <div class = "mini-fit">
            <div id="datagrid1" class="mini-datagrid"
                 style="width: 100%; height: 100%;"
                 url="${base}/pages/finance_manage/repayment/queryReverseList" idField="id"
                 showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
                 multiSelect = "true" allowResize="true"
                 showGroupsSummary="true" showSummaryRow="true" summaryPosition="bottom"
                 allowSortColumn = "true"
                 ondrawsummarycell="summaryRight">

                <div property="columns">
                    <div field="customerId" width="180" headerAlign="center" align="left" allowSort="true" data-options='{cacheName:"customer"}' renderer="commonRender">还款人</div>
                    <div field="phone" width="140" headerAlign="center" align="left" allowSort="false">电话</div>
                    <div field="address" width="200" headerAlign="center" align="left" allowSort="false">地址</div>
                    <div field="totalAvailableAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">可用销账金额</div>
                    <div field="totalAvailableAmount" width="140" headerAlign="center" align="center" allowSort="false" renderer="reversRender">销账分单选择</div>
                </div>
            </div>

        </div>


        <!-- 销账分单选择窗口 -->
        <div id="nativeBillSelectPanel" class="mini-window" title="销账分单选择" style="width:1400px;height:530px;"
             showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
             showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">

            <div property="footer" style="padding:10px;text-align: right">
                <a  class="mini-button" iconCls="icon-ok" onclick="saveReverse()">保存</a>
                <a  class="mini-button" iconCls="icon-close" onclick="closeNativeBillSelectPanel('nativeBillSelectPanel')">关闭</a>
            </div>

            <span>发货人名称:</span> <input id="customerName" name="customerName" emptyText="请输入发货人名称"  class="mini-textbox" required="true" enabled="false" requiredErrorText="发货人名称不能为空" />
            <span>发货人电话:</span> <input id="customerPhone" name="customerPhone" emptyText="请输入发货人电话"  class="mini-textbox" required="true" enabled="false" requiredErrorText="发货人电话不能为空" />
            <span>发货人地址:</span> <input id="customerAddress" name="customerAddress" emptyText="请输入发货人地址"  class="mini-textbox" required="true" enabled="false" requiredErrorText="发货人地址不能为空" />
            <span>可用余额:</span> <input id="customerTotalAvailableAmount" name="customerTotalAvailableAmount" emptyText="请输入可用余额"  class="mini-textbox" required="true" enabled="false" requiredErrorText="可用余额不能为空" />
            <span style="color: red">已选分单销账金额:</span> <input id="selectedReverseAmount" name="selectedReverseAmount" value = "0.00" emptyText="请输入已选分单销账金额"  class="mini-textbox" required="false" enabled="false" requiredErrorText="已选分单销账金额不能为零" />

            <div id="selectedReverseForm" style="width: 100%">
                <input id="keyDeliveryCustomerId" name="keyDeliveryCustomerId" emptyText="请输入发货人ID"  class="mini-hidden" required="true" enabled="false" enabled="false" requiredErrorText="请输入发货人ID不能为空" />
                <input id="keySettlementStatusId" name="keySettlementStatusId" emptyText="请输入结算状态ID"  class="mini-hidden" required="true" enabled="false" enabled="false" requiredErrorText="结算状态ID不能为空" />
                <div style="margin-top: 5px"></div>
                <span>分单号:</span> <input id="keyBillCode" name="keyBillCode" emptyText="请输入分单号"  class="mini-textbox" required="false"  requiredErrorText="分单号不能为空" />
                <span class="separator"></span>
                <span>开单日期：</span>
                <input id="keyOpenBillStartDate" name="keyOpenBillStartDate"  class="mini-datepicker"   format="yyyy-MM-dd"/>
                --
                <input id="keyOpenBillEndDate" name="keyOpenBillEndDate" class="mini-datepicker"  format="yyyy-MM-dd"/>
                <span class="separator"></span>
                <a class="mini-button" iconCls="icon-search" onclick="searchBill()">查询</a>
                <span class="separator"></span>
                <a class="mini-button" iconCls="icon-search" onclick="clearSearch('selectedReverseForm')">清空查询条件</a>
                <span class="separator"></span>
                <#download_grid id="downloadGrid2" theGridId="nativeBillDataGrid" theFileName="销账分单表"/>

                <div style="margin-top: 5px"></div>
                <span style="color: #0E2D5F;font-weight: bold">发货人待销账分单列表: (结算金额 = 实收金额 + 拉货调整金额)</span>
                <div style="margin-top: 5px"></div>
                <span style="color: darkred;font-weight: bold">可出现列表中的分单条件是:配载状态为全部配载，对账状态为已对账，结算状态为未结算</span>
                <div style="margin-top: 5px"></div>
                <div id="nativeBillDataGrid" class="mini-datagrid"
                     style="width: 100%; height: 350px;"
                     url="${base}/pages/native_bill_manage/queryBill?keyAccountCheckStatusId=432" idField="id"
                     showPager="true" pageSize="10" sizeList="[10,20,30,50,100]"
                     multiSelect = "true" allowResize="true"
                     showGroupsSummary="true" showSummaryRow="true" summaryPosition="bottom"
                     allowSortColumn = "true"
                     sortField="createTime"
                     sortOrder="desc"
                     onselect="rowSelected"
                     ondeselect="rowDeselect"
                     ondrawsummarycell="summaryRight"
                >
                    <div property="columns">
                        <div type="checkcolumn" ></div>
                        <div field="id" width="140" headerAlign="center" align="left" allowSort="true">分单号</div>
                        <div field="comment" width="140" headerAlign="center" align="center" allowSort="false">备注</div>
                        <div field="accountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">对账状态</div>
                        <div field="settlementAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum"><span style="color: red">结算金额</span></div>
                        <div field="settlementStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender"><span style="color: red">结算状态</span></div>
                        <div field="dropAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">拉货调整金</div>
                        <div field="dropStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">拉货状态</div>
                        <div field="totalAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">总金额</div>
                        <div field="actualAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">实收金额</div>
                        <div field="arrearsStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">分单欠款状态</div>
                        <div field="transportSpeciesId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">运输种类</div>
                        <div field="transportWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">承运方式</div>
                        <div field="transportScopeId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">运输范围</div>
                        <div field="cityId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"city"}' renderer="commonRender">营业部所在城市</div>
                        <div field="destCityId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"city"}' renderer="commonRender">目的市</div>

                        <div field="deliveryCustomerId" width="140" headerAlign="center" align="center" allowSort="true">发货人ID</div>
                        <div field="deliveryCustomerName" width="140" headerAlign="center" align="center" allowSort="true">发货人名称</div>
                        <div field="deliveryCustomerPhone" width="140" headerAlign="center" align="center" allowSort="true" renderer="commonDesensitization">发货人电话</div>
                        <div field="deliveryCustomerAddress" width="140" headerAlign="center" align="center" allowSort="true">发货人地址</div>

                        <div field="deliveryCustomerContactId" width="140" headerAlign="center" align="center" allowSort="true">发货人联系人ID</div>
                        <div field="deliveryCustomerContactName" width="140" headerAlign="center" align="center" allowSort="true">发货人联系人名称</div>
                        <div field="deliveryCustomerContactPhone" width="140" headerAlign="center" align="center" allowSort="true" renderer="commonDesensitization">发货人联系人人电话</div>

                        <div field="receiveCustomerName" width="140" headerAlign="center" align="center" allowSort="true">收货人名称</div>
                        <div field="receiveCustomerPhone" width="140" headerAlign="center" align="center" allowSort="true">收货人电话</div>
                        <div field="receiveCustomerAddress" width="140" headerAlign="center" align="center" allowSort="true">收货人地址</div>

                        <div field="pickUpPointId" width="140" headerAlign="center" align="center" allowSort="true">提货点ID</div>
                        <div field="pickUpPointName" width="140" headerAlign="center" align="center" allowSort="true">提货点名称</div>
                        <div field="pickUpPointPhone" width="140" headerAlign="center" align="center" allowSort="true">提货点电话</div>
                        <div field="pickUpPointAddress" width="140" headerAlign="center" align="center" allowSort="true">提货点地址</div>
                        <div field="pickUpGoodsWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">提货方式</div>

                        <div field="signChooseId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">签收方式</div>
                        <div field="deliveryCustomerSalemanId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysUser"}' renderer="commonRender">发货客户业务员</div>
                        <div field="airportId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airport"}' renderer="commonRender">始发机场</div>
                        <div field="flightDate" width="140" headerAlign="center" align="center" allowSort="true" dateFormat="yyyy-MM-dd" renderer="ondayRenderer">班次日期</div>
                        <div field="flightNo" width="140" headerAlign="center" align="center" allowSort="true">班次号ID</div>
                        <div field="flightName" width="140" headerAlign="center" align="center" allowSort="true">班次号名称</div>
                        <div field="airlinesId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airlines"}' renderer="commonRender">航空公司</div>
                        <div field="planTakeOffTime" width="140" headerAlign="center" align="center" allowSort="true">计划出发时间</div>
                        <div field="goodsName" width="140" headerAlign="center" align="center" allowSort="true" >货物名称</div>
                        <div field="goodsTypeId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">货物类型</div>
                        <div field="packingWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">包装方式</div>

                        <div field="volumeInformation" width="140" headerAlign="center" align="center" allowSort="true">体积信息</div>
                        <div field="totalNumber" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">总件数</div>
                        <div field="actualWeight" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">实际重量</div>
                        <div field="chargeableWeight" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">计费重量</div>
                        <div field="weightRate" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer">重量费率</div>
                        <div field="volume" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">体积</div>
                        <div field="volumeRate" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer">体积费率</div>
                        <div field="transportCost" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">运费合计</div>

                        <div field="declaredValue" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">声明价值</div>
                        <div field="insuranceRate" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" >保费费率</div>
                        <div field="insuranceFee" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">保费</div>
                        <div field="openBillDeliveryCharge" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">开单送货费</div>
                        <div field="agentDeliveryCharge" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">代理送货费</div>
                        <div field="tax" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">税金</div>
                        <div field="fuelSurcharge" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">燃油费</div>
                        <div field="collectionMoney" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">代收款</div>
                        <div field="otherCharges" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">其他费用</div>
                        <div field="otherChargesComment" width="140" headerAlign="center" align="center" allowSort="false">其他费用说明</div>
                        <div field="serviceCharge" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">业务费</div>
                        <div field="actualTransportCost" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">实收运费</div>

                        <div field="businessCostAllocationId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">是否分摊业务费</div>
                        <div field="businessCostAllocationTypeId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">业务费分摊类型</div>
                        <div field="businessCostComment" width="140" headerAlign="center" align="center" allowSort="false">业务费备注</div>

                        <div field="printActualWeight" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">打单实际重量</div>
                        <div field="printChargeableWeight" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" >打单计费重量</div>
                        <div field="printWeightRate" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">打单重量费率</div>
                        <div field="printVolume" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">打单体积</div>
                        <div field="printVolumeRate" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" >打单体积费率</div>

                        <div field="innerOperationCharge" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">内部操作费</div>
                        <div field="deliveryCustomerPaymentMethodId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">发货人付款方式</div>
                        <div field="deliveryCustomerPaymentAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">发货人付款金额</div>
                        <div field="receiveCustomerPaymentMethodId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">收货人付款方式</div>
                        <div field="receiveCustomerPaymentAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">收货人付款金额</div>

                        <div field="cashierId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">收银员</div>
                        <div field="openBillUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">开单人</div>
                        <div field="openBillDate" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">开单日期</div>
                        <div field="openBillDepartmentId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"department"}' renderer="commonRender">开单部门</div>
                        <div field="rollCallDepartmentId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"department"}' renderer="commonRender">点到部门</div>

                        <div field="billLoadStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">配载状态</div>
                        <div field="businessCostStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">业务费状态</div>
                        <div field="agentDeliveryChargeStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">代理送货费状态</div>

                        <div field="shareCost" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">分摊成本</div>
                        <div field="operatingCost" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">操作费</div>
                        <div field="grossProfit" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">毛利润</div>

                        <div field="createTime" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">创建时间</div>
                        <div field="createUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">创建用户</div>
                        <div field="updateTime" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">更新时间</div>
                        <div field="updateUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">更新用户</div>

                    </div>
                </div>

            </div>
        </div>



        <script type="text/javascript">
            mini.parse();

            let keyCustomerId = mini.get("keyCustomerId");

            let nativeBillSelectPanel = mini.get("nativeBillSelectPanel");

            // 主 grid
            let grid = mini.get("datagrid1");
            let nativeBillDataGrid = mini.get("nativeBillDataGrid");

            let customerName = mini.get("customerName");
            let customerPhone = mini.get("customerPhone");
            let customerAddress = mini.get("customerAddress");
            let customerTotalAvailableAmount = mini.get("customerTotalAvailableAmount");
            let keyDeliveryCustomerId = mini.get("keyDeliveryCustomerId");
            let keySettlementStatusId = mini.get("keySettlementStatusId");
            let selectedReverseAmount = mini.get("selectedReverseAmount");

            $(function () {
                // 加载列表数据
                grid.load();
            });

            function clearSearch(formName){
                let form = new mini.Form("#" + formName);
                form.clear();
            }

            /**
             * 根据查询条件查询
             */
            function searchReverse(){
                let form = new mini.Form("#queryForm");
                let data = form.getData(true);
                grid.load(data);
            }

            /**
             * 生成选择分单按钮
             */
            function reversRender(e){
                let viewHtml = "<a class='mini-button' style='width: 100px' onclick='showReversForm(\"" + public_round2(e.value)  + "\",\"" + e.record.customerId + "\",\"" + e.record.name + "\",\"" + e.record.phone + "\",\"" + e.record.address + "\")'>选择待销账分单</a>";
                return viewHtml;
            }

            /**
             * 弹出面板检索按钮
             * UNCLEARED(321, "未结清", "未结清"),
             CLEARED(322, "已结清", "已结清");
             */
            let settlementStatus = {uncleared:321, cleared:322};
            function searchBill(){
                let form = new mini.Form("#selectedReverseForm");
                let data = form.getData(true);
                nativeBillDataGrid.load(data);
                // 选中恢复0
                selectedReverseAmount.setValue(0);
            }

            /**
             * 弹出可结费用分单选择面板
             */
            function showReversForm(totalAvailableAmountValue,customerIdValue,customerNameValue,customerPhoneValue,customerAddressValue){
                customerTotalAvailableAmount.setValue(totalAvailableAmountValue);
                keyDeliveryCustomerId.setValue(customerIdValue);
                keySettlementStatusId.setValue(settlementStatus.uncleared);
                customerName.setValue(customerNameValue);
                customerPhone.setValue(customerPhoneValue);
                customerAddress.setValue(customerAddressValue);
                // 显示值
                public_showModelAtPos("nativeBillSelectPanel", "center", "middle");
                // 查询数据
                searchBill();
            }



            /**
             * 关闭弹出面板
             */
            function closeNativeBillSelectPanel(winId){
                // 清空
                customerTotalAvailableAmount.setValue(0);
                keyDeliveryCustomerId.setValue();
                customerName.setValue();
                customerPhone.setValue();
                customerAddress.setValue();
                selectedReverseAmount.setValue(0);
                nativeBillDataGrid.clearRows();

                // 关闭窗口
                let winObj = mini.get(winId);
                winObj.hide();
            }

            /**
             * 行选中时调用
             */
            function rowSelected(e){
                calcSelectedAmount();
            }

            /**
             * 行选取消选择时调用
             */
            function rowDeselect(e){
                calcSelectedAmount();
            }

            /**
             * 计算选择的结费总额
             */
            function calcSelectedAmount(){
                // 获取客户可用余额
                let customerTotalAvailableAmountValue = public_toNumber(customerTotalAvailableAmount.getValue());

                let selectItems = nativeBillDataGrid.getSelecteds();
                let newTotalAmount = 0;
                if(selectItems.length > 0){
                    for(let item of selectItems){
                        let settlementAmountValue = public_toNumber(item.settlementAmount);
                        newTotalAmount =  public_round2(settlementAmountValue + newTotalAmount);
                    }
                }
                selectedReverseAmount.setValue(newTotalAmount);
                if(customerTotalAvailableAmountValue < newTotalAmount){
                    showAlert("选择的待销账分单结算总额超过该客户的可用余额！");
                    return;
                }
            }

            /**
             * 弹出面板保存按钮点击响应方法
             */
            function saveReverse(){
                let customerTotalAvailableAmountValue = public_toNumber(customerTotalAvailableAmount.getValue());
                let selectedReverseAmountValue = public_toNumber(selectedReverseAmount.getValue());
                if(customerTotalAvailableAmountValue < selectedReverseAmountValue){
                    showAlert("选择的待销账分单结算总额超过该客户的可用余额,请取消部分选择的分单,确保可用余额大于或等于选择的分单结算金额！");
                    return;
                }

                // 发货人ID,就是发货客户 ID
                let keyDeliveryCustomerIdValue = keyDeliveryCustomerId.getValue();
                // 已经选择的分单
                let selectItems = nativeBillDataGrid.getSelecteds();

                if(selectItems.length==0){
                    showAlert("请选择待销账的分单！");
                    return;
                }

                // 待提交的对象
                let reverseObj = {customerId: keyDeliveryCustomerIdValue, billList: selectItems};

                mini.confirm(
                    "确定对选择的分单进行销账处理?",
                    "分单销账",
                    function(action) {
                        if (action == "ok") {
                            // 到此校验全部成功，可以入库了
                            let reverseObjUrl = "${base}/pages/finance_manage/repayment/addReverse";
                            let ret = public_getServerData(reverseObjUrl, reverseObj);
                            showAlert(ret.message,function (){
                                searchReverse();
                                searchBill();
                                customerTotalAvailableAmount.setValue(public_round2(customerTotalAvailableAmountValue - selectedReverseAmountValue));
                                selectedReverseAmount.setValue(0);
                            });
                        }
                    });
            }

            /**
             * 设置底部统计样式
             * @param e
             */
            function summaryRight(e){
                e.cellStyle="text-align:right;color:red;font-size:18px;";
            }

        </script>
    </body>
</html>